﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.Profile;
using System.Web.UI.WebControls;
using HySoft.Cash.Structure;
using HySoft.Cash.Business;

namespace PayRoller.Member
{
    public class MyProfileUpt : MemberParent, IRequiresSessionState
    {
        // Fields
        protected Button bnSave;
        protected Label lblTip;
        protected TextBox txtAltEmail1;
        protected TextBox txtAltEmail2;
        protected TextBox txtContactPerson;
        protected TextBox txtContactPhone1;
        protected TextBox txtContactPhone2;
        protected TextBox txtFax;
        protected TextBox txtMobile;
        protected TextBox txtPostalAddress;
        protected TextBox txtPreferredEmail;
        protected TextBox txtsPosition;

        // Methods
        protected void bnSave_Click(object sender, EventArgs e)
        {
            try
            {
                TorginfoBN obn = new TorginfoBN(this.Page);
                TorginfoDT detail = obn.Get(Convert.ToInt32(base.OrgSid));
                detail.Sid = Convert.ToInt32(base.OrgSid);
                detail.ContactPerson = this.txtContactPerson.Text;
                detail.sPosition = this.txtsPosition.Text;
                detail.PostalAddress = this.txtPostalAddress.Text;
                detail.ContactPhone1 = this.txtContactPhone1.Text;
                detail.ContactPhone2 = this.txtContactPhone2.Text;
                detail.Fax = this.txtFax.Text;
                detail.Mobile = this.txtMobile.Text;
                detail.PreferredEmail = this.txtPreferredEmail.Text;
                detail.AltEmail1 = this.txtAltEmail1.Text;
                detail.AltEmail2 = this.txtAltEmail2.Text;
                obn.Edit(detail);
                obn.Dispose();
                obn = null;
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
            }
            catch (Exception exception)
            {
                this.lblTip.Text = exception.Message;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.CheckLogin();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((base.OrgSid != "") && !this.Page.IsPostBack)
            {
                try
                {
                    TorginfoBN obn = new TorginfoBN(this.Page);
                    TorginfoDT odt = obn.Get(Convert.ToInt32(base.OrgSid));
                    this.txtContactPerson.Text = odt.ContactPerson;
                    this.txtsPosition.Text = odt.sPosition;
                    this.txtPostalAddress.Text = odt.PostalAddress;
                    this.txtContactPhone1.Text = odt.ContactPhone1;
                    this.txtContactPhone2.Text = odt.ContactPhone2;
                    this.txtFax.Text = odt.Fax;
                    this.txtMobile.Text = odt.Mobile;
                    this.txtPreferredEmail.Text = odt.PreferredEmail;
                    this.txtAltEmail1.Text = odt.AltEmail1;
                    this.txtAltEmail2.Text = odt.AltEmail2;
                    obn.Dispose();
                    obn = null;
                }
                catch (Exception exception)
                {
                    this.lblTip.Text = exception.Message;
                }
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
